﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_ItemAmount : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_ItemAmount ).FullName );

        public S_ItemAmount( L1ItemInstance item )
        {
            if ( item == null )
            {
                return;
            }

            buildPacket( item );
        }

        private void buildPacket( L1ItemInstance item )
        {
            // writeC(Opcodes.S_OPCODE_ITEMAMOUNT);
            // writeD(item.getId());
            // writeD(item.getCount());
            // writeC(0);
            // 3.0
            writeC( Opcodes.S_OPCODE_ITEMAMOUNT );
            writeD( item.getId() );
            writeS( item.getViewName() );
            writeD( item.getCount() );
            if ( !item.isIdentified() )
            { // 未鑑定の場合ステータスを送る必要はない
                writeC( 0 );
            }
            else
            {
                byte[] status = item.getStatusBytes();
                writeC( status.Length );
                foreach ( byte b in status )
                {
                    writeC( b );
                }
            }
            // 3.0 end
        }

        override
        public byte[] getContent()
        {
            return getBytes();
        }

        override
        public String getType()
        {
            return "[S] S_ItemAmount";
        }
    }
}